<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('课程信息')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <link th:href="@{/css/simplemde.min.css}" rel="stylesheet"/>
</head>
<body class="gray-bg">
<div>
    <div class="modal-footer">
        <div class="form-group">
            <label class="col-sm-2 control-label">标题：</label>
            <div class="col-sm-6">
                <input id="title" name="title" class="form-control" th:value="${title}" type="text">
            </div>
        </div>
        <button type="button" class="btn btn-primary" onclick="preview()">保存预览</button>
    </div>
    <input id="packagesId" name="packagesId" th:value="${id}" type="hidden">
    <input id="content" name="content" th:value="${content}" type="hidden">
    <input id="type" name="type" th:value="${type}" type="hidden">
    <div id="contentDetails"></div>
    <textarea></textarea>
</div>
<th:block th:include="include :: footer"/>
<script src="https://cdn.bootcss.com/simplemde/1.11.2/simplemde.min.js"></script>
<script>
    var simplemde = new SimpleMDE();
    var prefix = ctx + "system/courseContent";
    setTimeout(function () {
        var content = $("#content").val();
        simplemde.value(content);
    }, 1500)

    function submitHandler() {
        var testPlain = simplemde.value(),
            testMarkdown = simplemde.markdown(testPlain);
        var type = $("#type").val();
        var data = {"vendorPackageId": $("#packagesId").val(), "content": testPlain, "type": $("#type").val(), "title": $("#title").val()};
        $.operate.save(prefix + "/addAll", data);
    }

    function preview() {
        var testPlain = simplemde.value(),
            testMarkdown = simplemde.markdown(testPlain);
        var type = $("#type").val();
        var data = {"vendorPackageId": $("#packagesId").val(), "content": testPlain, "type": $("#type").val(), "title": $("#title").val()};

        $.ajax({
            type: "post",
            url: prefix + "/addAll",
            data: data,
            success: function(data) {
                var href = ctx + 'system/courseContent/preview?id=' + $("#packagesId").val()+'&type='+type;
                $.modal.open("文本编辑", href);
            }
        });

    }

</script>
</body>
</html>
